package My;

import java.util.Stack;

public class MyQueue {  //相当于利用临时变量栈来实现两个栈的逆置实现队列的操作，第一个栈的最后出的元素变成第二个栈第一个出的元素

    public Stack<Integer> stack1;
    public Stack<Integer> stack2;

    public MyQueue(){
        stack1=new Stack<>();
        stack2=new Stack<>();
    }

    public void push(int x){
        stack1.push(x);
    }
    public int poll(){
        if(isempty()){
            return -1;
        }
        if(stack2.empty()){
            while (!stack1.empty()){
                int tmp =stack1.pop();
                stack2.push(tmp);
            }
        }
        return  stack2.pop();
    }

    public  int peek(){
        if(isempty()){
            return -1;
        }
        if(stack2.empty()){
            while (!stack1.empty()){
                int tmp =stack1.pop();
                stack2.push(tmp);
            }
        }
        return  stack2.peek();
    }
    public  boolean isempty(){
        if(stack1.empty()&&stack2.empty()){
            return true;
        }
        return  false;
    }
}
